-- mechanical_bonus
-- create by panyl
-- 道具：  致命伤害

return {
    apply = function(source, target, classId, value)
        -- 能量齿轮效果
        local level = 0;
        local dbase = PropertyM.query(classId, "dbase") or {};
        local path = dbase["prop_path"];
        if not path then
            path = "mixed";
        end

        -- 机械师专属强化效果
        local prop = PropM.combine(source,  "mechanics", 1);
        level = PropM.apply(prop, level);
        if prop[3] > 0 then
            -- 触发特技发动事件
            EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
        end

        -- 状态，持续本层
        local condition = {
            ["end_round"] = -1,
        };

        if level > 0 then
            local arr;
            local num;
            for i = 1, level do
                arr = value[i];

                if #arr > 2 then
                    if arr[1] == 2 then
                        -- 百分比属性奖励
                        local attrigName = arr[2];
                        num = tonumber(source:queryAttrib("max_"..attrigName));
                        num = math.max(1, math.modf(num * arr[3] / 1000));

                        -- 可增加上限
                        if "hp" == attribName or "mp" == attribName then
                            attribName = "limit_" .. attribName;
                        end

                        BonusM.doBonus({arr[1], attrigName, num}, "apply_property");
                    end
                else
                    condition[arr[1]] = arr[2];
                end
            end
        end

        -- 状态
        CombatStatusM.applyStatus(target, "energy_gear", condition);

        -- 抛出事件
        EventMgr.fire(event.ADD_BUFF, { ["target"] = target});
    end,
};
